﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CNRegex.Web.Models;
using CNRegex.Enum;
using System.Configuration;
using CNRegex.Entity;
using CNRegex.Web.Base;
using CNRegex.Biz.BizAccess;
using CNRegex.Biz;

namespace CNRegex.Web.Controllers
{
	public class DesignPatternController : BaseController
	{
		private BizRegexTutorialCatalogContentComment bizRegexTutorialCatalogContentComment;
		private static Guid designPatternID = Guid.Parse(ConfigurationManager.AppSettings.Get(EnumAppSettings.DesignPatternTutorialID.ToString()));
		//
		// GET: /DesignPattern/

		public DesignPatternController()
		{

		}

		public ActionResult Index()
		{
			ModelTutorialTemplate model = new ModelTutorialTemplate(designPatternID, "DesignPattern", "Tutorial");
			return View(model);
		}

		public ActionResult Tutorial(Guid id, int? pageIndex)
		{
			ModelTutorialTemplateTutorialContent model = new ModelTutorialTemplateTutorialContent(id, designPatternID, "DesignPattern", "Tutorial") { PageIndex = pageIndex, CommentActionName = "Comment", CommentControllerName = "DesignPattern" };
			return View(model);
		}

		[HttpPost]
		[ValidateInput(false)]
		public ActionResult Comment(Guid? id, RegexTutorialCatalogContentComment model)
		{
			model.CommentDate = DateTime.Now;
			model.UserID = FrontContext.CurrentRegexUser.ID;
			bizRegexTutorialCatalogContentComment.Save(model);
			return RedirectToAction("Tutorial", new { id = id });
		}

	}
}
